Skip to content

feat: introduce otp login flow for us region#1373

Merged
cdnninja merged 4 commits into
Hyundai-Kia-Connect:masterfrom
renatkh:us_otp_login_flow
Dec 6, 2025
Merged

feat: introduce otp login flow for us region#1373
cdnninja merged 4 commits into
Hyundai-Kia-Connect:masterfrom
renatkh:us_otp_login_flow

Conversation

@renatkh

@renatkh renatkh commented Nov 1, 2025

Copy link
Copy Markdown
Contributor

Summary
Implements OTP (2FA) login flow for USA region and persists both rmtoken (remember token) and device_id to prevent repeated OTP prompts across Home Assistant restarts.
Keeps non-USA regions unchanged.
Adds minimal type annotations for Vehicle in a few entity modules (non-functional).

Functional changes
Config flow (config_flow.py)
Adds OTP steps for USA region: send_otp and input_otp_code
Stores rmtoken and device_id in the created entry’s data
Reuses stored rmtoken/device_id to avoid OTP on subsequent logins
Coordinator (coordinator.py)
Pre-seeds token with stored rmtoken/device_id before authentication
Persists updated rmtoken/device_id back to ConfigEntry after successful refresh
Uses a non-interactive OTP handler during runtime updates
Constants (const.py)
Adds CONF_RMTOKEN and CONF_DEVICE_ID for persistence
Translations (translations/en.json and localized variants if present)
Adds strings for OTP flow UI

Compatibility and migration
USA region: Existing entries are auto-updated; the first login may prompt for OTP, after which rmtoken/device_id are saved and reused
Other regions: No change
No user action required; if authentication gets stuck, removing and re-adding the integration will re-run the new flow

Security and privacy
rmtoken and device_id are stored in the integration’s ConfigEntry data (Home Assistant storage); treat this as sensitive material
Deleting the integration removes these values

Testing and validation
Verified OTP flow (send and validate), successful session establishment, and reuse of rmtoken/device_id across restarts for USA
Confirmed DataUpdateCoordinator refresh works without OTP prompts after initial verification
Compiled all modified modules with py_compile successfully

Notes
Requires hyundai_kia_connect_api library version that implements OTP and token/device_id support for USA
No breaking changes anticipated for non-USA users

How to test
Configure the integration for USA
Complete OTP once when prompted
Restart Home Assistant and verify no additional OTP prompt appears, and data updates continue normally

@renatkh

renatkh commented Nov 1, 2025

Copy link
Copy Markdown
Contributor Author

@renatkh

renatkh commented Dec 4, 2025

Copy link
Copy Markdown
Contributor Author

@cdnninja This is the pared PR that utilizes the merged API changes. Can I get it reviewed too?

@cdnninja

cdnninja commented Dec 4, 2025

Copy link
Copy Markdown
Collaborator

This will need a manifest bump for the api. I am thinking we do that first and release, give it a few days and merge this. Purely to confirm stability for other regions.

@renatkh

renatkh commented Dec 4, 2025

Copy link
Copy Markdown
Contributor Author

This will need a manifest bump for the api. I am thinking we do that first and release, give it a few days and merge this. Purely to confirm stability for other regions.

Is the manifest bump manual or automatic?

@cdnninja

cdnninja commented Dec 4, 2025

Copy link
Copy Markdown
Collaborator

The api version in manifest needs to be manually bumped. The release of the integration and its own version is automatic.

@renatkh

renatkh commented Dec 6, 2025

Copy link
Copy Markdown
Contributor Author

@cdnninja I have tested this branch with 3.51.1 api version, and everything works great. Do you want me to bump the manifest in this PR, or should the bump be separate?

@cdnninja

cdnninja commented Dec 6, 2025

Copy link
Copy Markdown
Collaborator

I am thinking separate PR so that we can release the API with all those changes and confirm nothing breaks in the process. My understanding is it should function with the current integration for all regions. Are you able to create a PR for that?

@renatkh

renatkh commented Dec 6, 2025

Copy link
Copy Markdown
Contributor Author

@cdnninja, I can't test this because the US version doesn't log in at all without these changes. So it is definitely in a broken state without this PR. If you can test EU login workflow or CA that would be great.

@cdnninja

cdnninja commented Dec 6, 2025

Copy link
Copy Markdown
Collaborator

I can't. I don't own one of these cars anymore. If you are around the next day let's add the api to this PR.

My ask is to keep an eye out for new regression on GitHub if a fix is needed.

@renatkh

renatkh commented Dec 6, 2025

Copy link
Copy Markdown
Contributor Author

@cdnninja Done. I am confident about the US side, and I will keep an eye out for new issues in other regions for the next week.

@cdnninja
cdnninja merged commit 8e73ccd into Hyundai-Kia-Connect:master Dec 6, 2025
4 checks passed
@renatkh
renatkh deleted the us_otp_login_flow branch December 6, 2025 18:48
cdnninja added a commit that referenced this pull request Dec 11, 2025
blka pushed a commit to blka/kia_uvo that referenced this pull request May 25, 2026
Summary
Implements OTP (2FA) login flow for USA region and persists both rmtoken
(remember token) and device_id to prevent repeated OTP prompts across
Home Assistant restarts.
Keeps non-USA regions unchanged.
Adds minimal type annotations for Vehicle in a few entity modules
(non-functional).

Functional changes
Config flow (config_flow.py)
Adds OTP steps for USA region: send_otp and input_otp_code
Stores rmtoken and device_id in the created entry’s data
Reuses stored rmtoken/device_id to avoid OTP on subsequent logins
Coordinator (coordinator.py)
Pre-seeds token with stored rmtoken/device_id before authentication
Persists updated rmtoken/device_id back to ConfigEntry after successful
refresh
Uses a non-interactive OTP handler during runtime updates
Constants (const.py)
Adds CONF_RMTOKEN and CONF_DEVICE_ID for persistence
Translations (translations/en.json and localized variants if present)
Adds strings for OTP flow UI

Compatibility and migration
USA region: Existing entries are auto-updated; the first login may
prompt for OTP, after which rmtoken/device_id are saved and reused
Other regions: No change
No user action required; if authentication gets stuck, removing and
re-adding the integration will re-run the new flow

Security and privacy
rmtoken and device_id are stored in the integration’s ConfigEntry data
(Home Assistant storage); treat this as sensitive material
Deleting the integration removes these values

Testing and validation
Verified OTP flow (send and validate), successful session establishment,
and reuse of rmtoken/device_id across restarts for USA
Confirmed DataUpdateCoordinator refresh works without OTP prompts after
initial verification
Compiled all modified modules with py_compile successfully

Notes
Requires hyundai_kia_connect_api library version that implements OTP and
token/device_id support for USA
No breaking changes anticipated for non-USA users

How to test
Configure the integration for USA
Complete OTP once when prompted
Restart Home Assistant and verify no additional OTP prompt appears, and
data updates continue normally

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants